package com.hxm.appGenealogy.Function;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hxm.appGenealogy.config.queryVo.QueryWrapperVO;
import com.hxm.appGenealogy.entity.Family;
import com.hxm.appGenealogy.entity.ResponDataVo;
import com.hxm.appGenealogy.mapper.FamilyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class FamilyFunction {


    @Autowired
    private FamilyMapper familyMapper;


    public ResponDataVo selectByid(Long id){
        Family family = familyMapper.selectById(id);
        return new ResponDataVo(family);
    }

    public ResponDataVo updateById(Family family){
        familyMapper.updateById(family);
        return new ResponDataVo(family);
    }

    public ResponDataVo selectGetListQuery(String query){
        QueryWrapper<Family> queryWrapper = QueryWrapperVO.getQueryWrapper(query);
        List<Family> families = familyMapper.selectList(queryWrapper);
        return new ResponDataVo(families);
    }

    public ResponDataVo selectGetOneQuery(String query){
        QueryWrapper<Family> queryWrapper = QueryWrapperVO.getQueryWrapper(query);
        Family families = familyMapper.selectOne(queryWrapper);
        return new ResponDataVo(families);
    }



    public ResponDataVo insert(Family family){
        familyMapper.insert(family);
        return new ResponDataVo(family);
    }


    public void del(Family family){
        familyMapper.deleteById(family.getId());
    }

}











